package com.sptpc.demo.model;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.Type;
import org.joda.money.Money;

import javax.persistence.*;
import java.time.LocalDateTime;
import java.util.List;

//订单
@Entity
@Table(name = "t_order")
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class Order {
    @ManyToMany
    @JoinTable(name = "t_order_drink", joinColumns = {@JoinColumn(name = "drink_order_id")})
//    @OrderBy("createTime")
    private List<Drink> items;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Integer id;
    @Column(updatable = false)
    @CreationTimestamp
    private LocalDateTime createTime;
    private String customer;
    private Integer state;
    @Type(type = "org.jadira.usertype.moneyandcurrency.joda.PersistentMoneyAmount",
            parameters = {@org.hibernate.annotations.Parameter(name = "currencyCode", value = "CNY")})
    private Money price;
    @Override
    public String toString() {
        return "Order{" +
                "id =" + id +
                ", customer='" + customer +
                ", state=" + state +
                ", items=" + items +
                ", price=" + price.getAmount() +
                "} ";
    }

}
